<?php 
	$sup_id = $sup_name = $sup_address = $sup_contact1 = $sup_contact2 = "";
	$action ="insert";
	$btn = "Save";
	
	if(isset($_POST['btnSubmit'])){		
		$sql="INSERT INTO tbl_suppliers (sup_id,sup_name,sup_address,sup_contact1, sup_contact2)
		VALUES(
			'$_POST[txtCusID]',
			'$_POST[txtCusName]',
			'$_POST[txtCusAddress]',
			'$_POST[txtCusContact1]',
			'$_POST[txtCusContact2]')";
	
		mysql_query($sql);
		pageRedirect("index.php?page=add_stock&action=add_stock_check_out&","$_POST[txtCusName]&one=, this supplier added...!");
	}
	if(!isset($_GET['id'])){
		// max id
		$sql="SELECT id FROM tbl_suppliers ORDER BY id DESC";
		$result=query($sql);
		$row=fetch_array($result);
		$id=$row["id"] +1;
		$sup_id="S".$id;
	}
?>

<form action="index.php?page=supplier_list&action=supplier_addnew" method="post">
	<table class="bordered" width="770">
        <thead>
            <tr>
                <th>Please insert your Supplier information:<br /><span class="red">* require feild</span></th>
            </tr>
        </thead>
	</table>
    <table class="bordered" width="770">
		<tr>
			<td colspan="2">
            	<label><span class="red">*</span> Supplier ID:</label>
				<input type="text" class="txtID" name="txtCusID" value="<?php echo $sup_id;?>" /> </td>           
            <td colspan="2">
            	<label><span class="red">*</span> Supplier Name:</label>
            	<input type="text" class="txtCusName" name="txtCusName" value="<?php echo $sup_name ?>" /> 
            </td>
		</tr>
        <tr>
        	<td colspan="4">
            	<label>Address:</label>
				<input type="text" class="txtCusAddress" name="txtCusAddress" value="<?php echo $sup_address ?>" />
           	</td>
		</tr>
        <tr>
			<td colspan="2">
            	<label>Contact1:</label>
				<input type="text" class="txtCusContact1" name="txtCusContact1" value="<?php echo $sup_contact1 ?>" />
            </td>
            <td colspan="2">
            	<label>Contact2:</label>
            	<input type="text" class="txtCusContact2" name="txtCusContact2" value="<?php echo $sup_contact2 ?>" />
            </td>
		</tr>
		<tr>
			<td colspan="4"><input type="submit" class="btnSubmit" name="btnSubmit" value="<?php echo $btn ?>" />&nbsp; 
            <input type="button" class="btnSubmit" name="btncancel" value="Cancel" onclick="redirect('index.php?page=add_stock_new&action=add_stock_new')" /></td>
		</tr>
	</table>
</form>